package cn.elves.model.activity.service.stateflow;

import cn.elves.model.activity.entity.constant.ActivityStateConstants;
import cn.elves.model.activity.entity.po.Activity;
import cn.elves.model.activity.service.ActivityService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;

import javax.annotation.Resource;

public abstract class AbstractStateUpdater implements StateHandle {

    @Resource
    protected ActivityService activityService;


    @Override
    public Boolean doArraignment(Long activityId, Integer curState) {
        throw new UnsupportedOperationException(activityId + " 从 " + curState + "状态变更为 " + ActivityStateConstants.ARRAIGNMENT + "状态的行为不被允许");
    }

    @Override
    public Boolean doCheckPass(Long activityId, Integer curState) {
        throw new UnsupportedOperationException(activityId + " 从 " + curState + "状态变更为 " + ActivityStateConstants.PASS + "状态的行为不被允许");
    }

    @Override
    public Boolean doCheckRefuse(Long activityId, Integer curState) {
        throw new UnsupportedOperationException(activityId + " 从 " + curState + "状态变更为 " + ActivityStateConstants.REFUSE + "状态的行为不被允许");
    }

    @Override
    public Boolean doCheckRevoke(Long activityId, Integer curState) {
        throw new UnsupportedOperationException(activityId + " 从 " + curState + "状态变更为 " + ActivityStateConstants.REVOKE + "状态的行为不被允许");
    }

    @Override
    public Boolean doClose(Long activityId, Integer curState) {
        throw new UnsupportedOperationException(activityId + " 从 " + curState + "状态变更为 " + ActivityStateConstants.CLOSE + "状态的行为不被允许");
    }

    @Override
    public Boolean doOpen(Long activityId, Integer curState) {
        throw new UnsupportedOperationException(activityId + " 从 " + curState + "状态变更为 " + ActivityStateConstants.OPEN + "状态的行为不被允许");
    }

    @Override
    public Boolean doDoing(Long activityId, Integer curState) {
        throw new UnsupportedOperationException(activityId + " 从 " + curState + "状态变更为 " + ActivityStateConstants.DOING + "状态的行为不被允许");
    }


    protected Boolean updateState(Long activityId, Integer curState, Integer toState) {
        Activity activity = new Activity();
        activity.setState(toState);
        return activityService.update(activity, new UpdateWrapper<Activity>().eq("id", activity).eq("state", curState));
    }


}
